package com.gti.mobilsafe.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {

	public static String encode(String text){
		try {
			MessageDigest digest = MessageDigest.getInstance("MD5");
			byte[] result = digest.digest(text.getBytes());
			StringBuffer sb = new StringBuffer();
			for(byte b : result){
				int code = b&0xff;
				String s = Integer.toHexString(code);
				if(s.length()==1){
					sb.append("0");
					sb.append(s);
				}else{
					sb.append(s);
				}
			}
			return sb.toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			//CAN'T REACHE
			return "";
		}
	}
}
